Skip to content

fix: reduce INP latency for receipt image interactions#96089

Open
nabi-ebrahimi wants to merge 4 commits into
Expensify:mainfrom
nabi-ebrahimi:fix/inp-receipt-image-interaction
Open

fix: reduce INP latency for receipt image interactions#96089
nabi-ebrahimi wants to merge 4 commits into
Expensify:mainfrom
nabi-ebrahimi:fix/inp-receipt-image-interaction

Conversation

@nabi-ebrahimi

@nabi-ebrahimi nabi-ebrahimi commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Explanation of Change

This PR improves the slow Receipt-Image INP interaction on web.

The Receipt-Image interaction happens when a user taps a receipt image in ReportActionItemImage to open the receipt preview modal. Previously, the press handler called Navigation.navigate() immediately, so heavier modal navigation work could begin before the browser had a chance to paint the click feedback.

This PR routes receipt modal navigation through platform-specific deferReceiptNavigation helpers. On web, the helper waits for a double requestAnimationFrame() paint boundary before calling Navigation.navigate(). Native/default platforms keep the existing immediate navigation behavior.

This does not remove the modal navigation work itself; it moves that work until after the browser has had a chance to paint the receipt click feedback, improving the measured and perceived responsiveness of the Receipt-Image interaction on web.

Fixed Issues

$ #85595
PROPOSAL: #85595 (comment)

Tests

  1. First, build the app for the web.

  2. Open the app in Chrome with the Web Vitals extension enabled.

  3. Navigate to a report that has an expense with a receipt image.

  4. Refresh the page to reset the current page INP measurement.

  5. Click the receipt image to open the receipt preview modal.

  6. After the receipt modal opens, check the Web Vitals extension and record the INP value for the receipt image interaction.

  7. Do not measure the Back/Close interaction as part of this test. Record the receipt image result before clicking Back.

  8. Repeat the same steps before and after the change for comparison.

  9. Verify that the receipt preview modal opens successfully and the Receipt-Image interaction on the web shows improved INP (or no regression compared to the baseline). The Back/Close interaction should be excluded from this measurement.

  • Verify that no errors appear in the JS console

Offline tests

Same as Tests.

QA Steps

Same as Tests.

// TODO: These must be filled out, or the issue title must include "[No QA]."

  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If new assets were added or existing ones were modified, I verified that:
    • The assets are optimized and compressed (for SVG files, run npm run compress-svg)
    • The assets load correctly across all supported platforms.
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • I added unit tests for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

Android: Native
Screen.Recording.2026-07-15.at.10.57.03.AM.mov
Android: mWeb Chrome
Screen_Recording_20260715_115043_Chrome.mp4
iOS: Native
Screen.Recording.2026-07-15.at.11.52.29.AM.mov
iOS: mWeb Safari
Screen.Recording.2026-07-15.at.11.56.41.AM.mov
MacOS: Chrome / Safari
Screencast.From.2026-07-15.10-05-10.mp4

@codecov

codecov Bot commented Jul 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ Changes either increased or maintained existing code coverage, great job!

Files with missing lines Coverage Δ
...ponents/ReportActionItem/ReportActionItemImage.tsx 72.13% <50.00%> (+2.77%) ⬆️
...ponents/ReportActionItem/deferReceiptNavigation.ts 0.00% <0.00%> (ø)
...nts/ReportActionItem/deferReceiptNavigation.web.ts 0.00% <0.00%> (ø)
... and 12 files with indirect coverage changes

@nabi-ebrahimi nabi-ebrahimi marked this pull request as ready for review July 15, 2026 07:43
@nabi-ebrahimi nabi-ebrahimi requested review from a team as code owners July 15, 2026 07:43
@melvin-bot melvin-bot Bot requested review from marufsharifi and trjExpensify and removed request for a team July 15, 2026 07:43
@melvin-bot

melvin-bot Bot commented Jul 15, 2026

Copy link
Copy Markdown

@marufsharifi Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@melvin-bot melvin-bot Bot removed the request for review from a team July 15, 2026 07:43
Comment thread src/components/ReportActionItem/ReportActionItemImage.tsx Outdated
Comment thread src/components/ReportActionItem/ReportActionItemImage.tsx Outdated
@marufsharifi

Copy link
Copy Markdown
Contributor

@nabi-ebrahimi, could you please address the AI comments?

@trjExpensify trjExpensify removed their request for review July 15, 2026 12:15
@trjExpensify

Copy link
Copy Markdown
Contributor

PR doesn’t need product input as a perf refactor PR. Unassigning and unsubscribing myself.

@nabi-ebrahimi

Copy link
Copy Markdown
Contributor Author

Hi @marufsharifi, thank you for taking the time to review.

I’ve addressed both AI comments by removing the manual useCallback and moving the web/native navigation scheduling into platform-specific deferReceiptNavigation helpers.

Could you please review again when you have a chance?

@marufsharifi

Copy link
Copy Markdown
Contributor

@MelvinBot review

@MelvinBot

Copy link
Copy Markdown
Contributor

Review

The approach is sound and the change is minimal. Deferring Navigation.navigate() past a paint boundary on web is a legitimate way to improve the Receipt-Image INP, and the platform split (immediate on native via deferReceiptNavigation.ts, double-rAF on web via deferReceiptNavigation.web.ts) is clean. Using a double requestAnimationFrame is the correct idiom here — a single rAF callback runs before the next paint, so the second one is what guarantees the click-feedback paint actually happened before the heavier navigation work starts.

A few non-blocking points worth a look:

Details
  1. "Stable callback" in the description is slightly inaccurate. navigateToReceipt is a plain function recreated on every render; it's only stable because React Compiler memoizes it (same as the previous inline arrow). The real win is the rAF deferral, not callback stability. Just worth aligning the wording so reviewers aren't looking for a useCallback that intentionally isn't there.

  2. What this actually improves. The double rAF lets the browser paint the click feedback first, which lowers the INP attributed to the tap — but the modal navigation still costs the same and appears at roughly the same wall-clock time. This is a perceived-responsiveness win, not a reduction in total work. That's the right goal for INP, just good to be explicit about in the issue.

  3. No test coverage on the new helpers (codecov shows both deferReceiptNavigation files at 0%), while the author checklist claims unit tests were added. The helpers are trivial so the risk is low, but a small unit test asserting the web variant defers and the native variant calls through synchronously would lock in the platform contract cheaply.

  4. Naming/reuse (optional). deferReceiptNavigation is a receipt-specific name for what is really a generic "defer to next paint" utility that doesn't reference receipts at all. Since the parent issue is about INP interactions broadly, if this pattern is likely to be reused elsewhere, a generic helper (e.g. deferToNextPaint) in src/libs might be a better home. Fine to keep it local and scoped for now.

  5. Minor edge case. With the 2-frame delay, a rapid double-tap could queue two navigations before the first fires. In practice Navigation should dedupe this, but worth a quick manual check that double-tapping the receipt doesn't stack modals.

Nothing here blocks merge from a code-correctness standpoint — items 1–2 are wording, 3–5 are polish. The perf claim itself (INP improvement) can't be verified from the diff; it relies on the before/after Web Vitals measurements in the test steps.

@marufsharifi

Copy link
Copy Markdown
Contributor

@nabi-ebrahimi, could you please take a look at the above comment? thanks.

@nabi-ebrahimi

Copy link
Copy Markdown
Contributor Author

@nabi-ebrahimi, could you please take a look at the above comment? thanks.

Hi @marufsharifi, thank you for the review.

I’ve addressed the feedback and updated the explanation of changes to clarify that this PR defers receipt modal navigation on web until after a double requestAnimationFrame() paint boundary, while preserving the existing immediate navigation behavior on native.

I also tested the double-click case and could not reproduce any duplicate receipt modal or duplicate navigation issue.

Could you please review again when you have a chance?

@marufsharifi

marufsharifi commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Reviewer Checklist

  • I have verified the author checklist is complete (all boxes are checked off).
  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
  • I checked that screenshots or videos are included for tests on all platforms
  • I included screenshots or videos for tests on all platforms
  • I verified that the composer does not automatically focus or open the keyboard on mobile unless explicitly intended. This includes checking that returning the app from the background does not unexpectedly open the keyboard.
  • I verified tests pass on all platforms & I tested again on:
    • Android: HybridApp
    • Android: mWeb Chrome
    • iOS: HybridApp
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • I verified proper code patterns were followed (see Reviewing the code)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I verified that this PR follows the guidelines as stated in the Review Guidelines
  • I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG)
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • For any bug fix or new feature in this PR, I verified that sufficient unit tests are included to prevent regressions in this flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

Android: HybridApp
Android: mWeb Chrome
iOS: HybridApp
iOS: mWeb Safari
MacOS: Chrome / Safari
Screen.Recording.2026-07-16.at.5.23.08.PM.mov

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants